import apis from "../../http/apis/apis.js"

export default {
    namespaced: true,
    state: {
        ordersData: [],
        total: 0,
        currentPage: 1,
        pageSize: 1,
        pages: "",
        searchData: {
            // _id: "",
            name: "",
            address: "",
            startTime: "",
            searchType: "4",
        },

    },
    mutations: {
        //获取列表，数据修改
        getOrdersData(state, data) {
            state.ordersData = data.data.ordersData
            state.total = data.data.total
        },
        //查询数据
        searchOrders(state, searchData) {
            state.searchData = searchData
            state.currentPage = 1
        },
        //改变显示条数
        changePageSize(state, pageSize) {
            state.pageSize = pageSize;
        },
        //改变当前页
        changeCurrentPage(state, currentPage) {
            state.currentPage = currentPage
        }
    },
    actions: {
        //获取订单列表
        async getOrders(context) {
            const { data } = await apis.orders.getOrders({
                searchData: context.state.searchData,
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize
            });
            console.log(data);
            if (data.status) {
                context.commit('getOrdersData', data);
            }
        },
        //删除订单
        async deleteOrders(context, _id) {
            const { data } = await apis.orders.deleteOrders({ _id });
            if (data.status) {
                alert(data.message);
                context.dispatch('getOrders')
            }
        }
    },
    modules: {
    }
}